package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.LiftTaskMapper;
import me.zhengjie.pojo.entity.LiftTask;
import me.zhengjie.sqlservice.LiftTaskService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class LiftTaskServiceImpl extends ServiceImpl<LiftTaskMapper, LiftTask> implements LiftTaskService {
    private final LiftTaskMapper liftTaskMapper;

    @Override
    public LiftTask selectLiftCode(String liftCode) {
        LambdaQueryWrapper<LiftTask> liftTaskLambdaQueryWrapper = new LambdaQueryWrapper<>();
        liftTaskLambdaQueryWrapper.eq(LiftTask::getLiftCode,liftCode);
        return liftTaskMapper.selectOne(liftTaskLambdaQueryWrapper);
    }

    @Override
    public boolean insertLiftTask(LiftTask liftTaskInsert) {
        return liftTaskMapper.insert(liftTaskInsert) >0;
    }

    @Override
    public List<LiftTask> selectAll() {
        return liftTaskMapper.selectList(null);
    }

    @Override
    public boolean updateStatus(Integer id, String status) {
        LambdaUpdateWrapper<LiftTask> liftTaskLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        liftTaskLambdaUpdateWrapper.set(LiftTask::getStatus,status)
                .set(LiftTask::getUpdateTime, LocalDateTime.now())
                .eq(LiftTask::getId,id);
        return liftTaskMapper.update(null,liftTaskLambdaUpdateWrapper) >0;
    }

    @Override
    public boolean deleteId(Integer id) {
        return liftTaskMapper.deleteById(id) >0;
    }

    @Override
    public LiftTask selectLIftTask(String taskCode) {
        LambdaQueryWrapper<LiftTask> liftTaskLambdaQueryWrapper = new LambdaQueryWrapper<>();
        liftTaskLambdaQueryWrapper.eq(LiftTask::getTaskCode,taskCode);
        return liftTaskMapper.selectOne(liftTaskLambdaQueryWrapper);
    }


}
